﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using EkStudio.com.common.clipboard;
using EkStudio.com.bean.xml.BillModule;

namespace EkStudio.com.ui.form
{
    public partial class CreateModuleForm : DevExpress.XtraEditors.XtraForm
    {
        private string caption = "";
        private string key = "";
        private object copyForm = null;


        public CreateModuleForm(ProjectRootPanel root,string caption,string title)
        {
            InitializeComponent();
            Text = string.Format("新建{0}{1}",caption, title.Length>0?string.Format("-{0}",title):"");
            labelOne.Text = string.Format("{0}标签", caption);
            labelTwo.Text = string.Format("{0}名称", caption);
            if(JClipboard.ContainData())
            {
                if(JClipboard.Paste()[0] is BillModuleItem)
                {
                    BillModuleItem it = JClipboard.Paste()[0] as BillModuleItem;
                    CopyCheckBox.Checked = true;
                    FromBillSource.Text = it.getCaption();
                    copyForm = it;
                }
            }
            
        }

        public string Caption
        {
            get
            {
                return caption;
            }

            set
            {
                caption = value;
            }
        }

        public string Key
        {
            get
            {
                return key;
            }

            set
            {
                key = value;
            }
        }

        public object CopyForm
        {
            get { return copyForm; }
        }

        private void BtnSubmit_Click(object sender, EventArgs e)
        {
            bool result = true;
            if(InputCaption.Text.Trim() == "")
            {
                labelError.Text = "标签不可为空，请重新填写";
                result = false;
                InputCaption.Focus();
            }
            if(result&&InputKey.Text.Trim() == "")
            {
                labelError.Text = "名称不可为空,请重新填写";
                result = false;
                InputKey.Focus();
            }
            if (result)
            {
                this.key = InputKey.Text.Trim();
                this.caption = InputCaption.Text.Trim();
                if(!CopyCheckBox.Checked)
                {
                    copyForm = null;
                }
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        private void InputCaption_EditValueChanged(object sender, EventArgs e)
        {
            this.labelError.Text = "";
        }

        private void InputKey_EditValueChanged(object sender, EventArgs e)
        {
            labelError.Text = "";
        }
    }
}